`
https://leetcode.cn/problems/minimum-add-to-make-parentheses-valid/
`

/**
 * @param {string} s
 * @return {number}
 */
var minAddToMakeValid = function (s) {
  let needLeft = 0, needRight = 0

  for (const c of s) {
    if (c === '(') {
      needRight += 1
    } else {
      needRight -= 1

      if (needRight === -1) {
        needRight = 0
        needLeft += 1
      }
    }
  }

  return needLeft + needRight
};